class Solution:
    def beautifulBouquet(self, flowers: List[int], cnt: int) -> int:
        ans = 0
        left = 0
        right = 0
        dict1 = {}
        mod = 1000000007
        while right < len(flowers):
            flower = flowers[right]
            if flower not in dict1:
                dict1[flower] = 1
            else:
                dict1[flower] += 1
            while dict1[flower] > cnt :
                dict1[flowers[left]] -= 1
                left += 1
            ans += right - left + 1
            right += 1
            ans %= mod
        return ans